home *** CD-ROM | disk | FTP | other *** search
- package netscape.ldap.client;
-
- import java.io.IOException;
- import java.io.OutputStream;
- import netscape.ldap.ber.stream.BERConstruct;
- import netscape.ldap.ber.stream.BERElement;
- import netscape.ldap.ber.stream.BERInteger;
- import netscape.ldap.ber.stream.BERIntegral;
- import netscape.ldap.ber.stream.BERSequence;
- import netscape.ldap.ber.stream.BERTag;
- import netscape.ldap.client.opers.JDAPAddResponse;
- import netscape.ldap.client.opers.JDAPBindResponse;
- import netscape.ldap.client.opers.JDAPCompareResponse;
- import netscape.ldap.client.opers.JDAPDeleteResponse;
- import netscape.ldap.client.opers.JDAPExtendedResponse;
- import netscape.ldap.client.opers.JDAPModifyRDNResponse;
- import netscape.ldap.client.opers.JDAPModifyResponse;
- import netscape.ldap.client.opers.JDAPProtocolOp;
- import netscape.ldap.client.opers.JDAPSearchResponse;
- import netscape.ldap.client.opers.JDAPSearchResult;
- import netscape.ldap.client.opers.JDAPSearchResultReference;
-
- public class JDAPMessage {
- protected int m_msgid;
- protected JDAPProtocolOp m_protocolOp;
- protected JDAPControl[] m_controls;
-
- public JDAPMessage(int var1, JDAPProtocolOp var2) {
- this.m_msgid = var1;
- this.m_protocolOp = var2;
- }
-
- public JDAPMessage(int var1, JDAPProtocolOp var2, JDAPControl[] var3) {
- this.m_msgid = var1;
- this.m_protocolOp = var2;
- this.m_controls = var3;
- }
-
- public JDAPMessage(BERElement var1) throws IOException {
- if (var1.getType() != 48) {
- throw new IOException("SEQUENCE in jdap message expected");
- } else {
- BERSequence var2 = (BERSequence)var1;
- BERInteger var3 = (BERInteger)((BERConstruct)var2).elementAt(0);
- this.m_msgid = ((BERIntegral)var3).getValue();
- BERElement var4 = ((BERConstruct)var2).elementAt(1);
- if (var4.getType() != -1) {
- throw new IOException("TAG in protocol operation is expected");
- } else {
- BERTag var5 = (BERTag)var4;
- switch (var5.getTag() & 31) {
- case 1:
- this.m_protocolOp = new JDAPBindResponse(var4);
- break;
- case 3:
- case 5:
- this.m_protocolOp = new JDAPSearchResult(var4);
- break;
- case 4:
- this.m_protocolOp = new JDAPSearchResponse(var4);
- break;
- case 7:
- this.m_protocolOp = new JDAPModifyResponse(var4);
- break;
- case 9:
- this.m_protocolOp = new JDAPAddResponse(var4);
- break;
- case 11:
- this.m_protocolOp = new JDAPDeleteResponse(var4);
- break;
- case 13:
- this.m_protocolOp = new JDAPModifyRDNResponse(var4);
- break;
- case 15:
- this.m_protocolOp = new JDAPCompareResponse(var4);
- break;
- case 19:
- this.m_protocolOp = new JDAPSearchResultReference(var4);
- break;
- case 24:
- this.m_protocolOp = new JDAPExtendedResponse(var4);
- break;
- default:
- throw new IOException("Unknown rotocol operation");
- }
-
- if (((BERConstruct)var2).size() >= 3) {
- var5 = (BERTag)((BERConstruct)var2).elementAt(2);
- if (var5.getTag() == 160) {
- BERSequence var6 = (BERSequence)var5.getValue();
- this.m_controls = new JDAPControl[((BERConstruct)var6).size()];
-
- for(int var7 = 0; var7 < ((BERConstruct)var6).size(); ++var7) {
- this.m_controls[var7] = new JDAPControl(((BERConstruct)var6).elementAt(var7));
- }
- }
- }
-
- }
- }
- }
-
- public int getId() {
- return this.m_msgid;
- }
-
- public JDAPProtocolOp getProtocolOp() {
- return this.m_protocolOp;
- }
-
- public JDAPControl[] getControls() {
- return this.m_controls;
- }
-
- public void write(OutputStream var1) throws IOException {
- BERSequence var2 = new BERSequence();
- BERInteger var3 = new BERInteger(this.m_msgid);
- ((BERConstruct)var2).addElement(var3);
- BERElement var4 = this.m_protocolOp.getBERElement();
- if (var4 == null) {
- throw new IOException("Bad BER element");
- } else {
- ((BERConstruct)var2).addElement(var4);
- if (this.m_controls != null) {
- BERSequence var5 = new BERSequence();
-
- for(int var6 = 0; var6 < this.m_controls.length; ++var6) {
- ((BERConstruct)var5).addElement(this.m_controls[var6].getBERElement());
- }
-
- BERTag var7 = new BERTag(160, var5, true);
- ((BERConstruct)var2).addElement(var7);
- }
-
- ((BERConstruct)var2).write(var1);
- }
- }
-
- public String toString() {
- return "[JDAPMessage] " + this.m_msgid + " " + this.m_protocolOp.toString();
- }
- }
-